from Products.KnowledgeEngine.KERL.Tokens.Token import Token
from Products.KnowledgeEngine.KERL.Operators import *
from Products.KnowledgeEngine.Services.MySQLFiveAssessmentStorageService.MySQLFiveAssessmentStorageService import qstr, qlist
from DateTime import DateTime
   
import types
   
class ModelIs(SimpleOperator):
    
    def execute(self, assessment):
        
        return self.a.getObject().getIdentity() == str(self.b)
    
    def toSQL(self):
        
        return "modelIdentity = " + qstr( self.a.getObject().getIdentity() )
    
   
   
class ModelToken(Token):
                
    _implements = Token._implements + ("ComponentToken",)
                
    operators = Token.operators.copy()
    
    operators.update( {
        'is': ModelIs
        
    })
                
    def __init__(self, object, namespace):
        """ Token wraps this object """
        
        if not object:
            raise "Creating ComponentToken without a component"
        
        self.object    = object
        self.namespace = namespace                        
                
    def toEnglish(self):
        """ Compiles this token into english """
        
        return "Model: %s (%s)" % (self.object.getIdentity(), self.object.title_or_id())

   
    def toKERL(self):
        return "'model'"
    